package xin.lms.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import xin.core.jpa.JpaConstant;
import lombok.*;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <pre>
 * Jwt Token Log
 * </pre>
 *
 * @author lixin@outlook.com
 * @version 1.0
 * @since 2017/12/12 9:18
 */
@Entity
@Table(name = "sys_jwt_log")
@Data
@ToString
@ApiModel
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Jwtlog implements Serializable {

    @Id
    @Column(length = JpaConstant.UidColumnLength)
    private String id;

    @Column(length = JpaConstant.DescriptionColumnLength)
    private String secret;

    @Column(length = JpaConstant.DescriptionColumnLength)
    private String token;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @Column
    private LocalDateTime tokenTime;

    @Column
    private Integer tokenStatus;

    public enum TokenStatus{
        /**
         * 正常
         */
        NORMAL(0),

        /**
         * 已刷新
         */
        REFRESH(1),

        /**
         * 已登出
         */
        EXIT(2),

        /**
         * 已过期
         */
        EXPIRED(3);

        private int value;

        TokenStatus(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }

        public boolean valueEquals(int number) {
            return value == number;
        }
    }
}